module Manager {

    export class GameInfo extends ui.GameInfoUI {

        constructor() {
            super();

            this.pauseBtn.on("click", this, this.onPauseBtnClick);
            this.playBtn.on("click", this, this.onPlayBtnClick);
            this.startOrRestart();
        }

        public startOrRestart(): void {
            this.notice.text = "";
            this.setHp(5);
            this.setLevel(0);
            this.setScore(0);
        }

        public onLoop() {
            this.setHp(DataManager.getInstance().blood);
            this.setLevel(DataManager.getInstance().level);
            this.setScore(DataManager.getInstance().score);
        }
        public pause() {}
        public resume() {}
        public stop() {}

        private onPauseBtnClick(e: Laya.Event): void {
            this.pauseBtn.visible = false;
            this.playBtn.visible = true;

            e.stopPropagation();
            this.notice.text = "!!! Game Pause !!!\nPress Anywhere To Continue!";
            gameInstance.pause();
            Laya.stage.on("click", this, this.onStageClick);
        }

        private onPlayBtnClick(e: Laya.Event): void {
            this.pauseBtn.visible = true;
            this.playBtn.visible = false;

            e.stopPropagation();
            this.notice.text = "";
            this.onStageClick();
        }

        private onStageClick(): void {
            this.pauseBtn.visible = true;
            this.playBtn.visible = false;
            
            gameInstance.resume();
            this.notice.text = "";
        }

        public setHp(num: number): void {
            if (num < 0) num = 0;

            this.blood.text = "Hp:" + num;
        }

        public setLevel(num: number): void {
            if (num < 0) num = 0;
            this.level.text = "Level:" + num;
        }

        public setScore(num: number): void {
            if (num < 0) num = 0;
            this.score.text = "Score:" + num;
        }
    }
}